
(
    function fetch(url){
        console.log("fetchfetchfetch")
        
        return new Promise((reslove,reject)=>{
            var idx = location.href.lastIndexOf("/")
            var relative = location.href.substring(0,idx+1)
            console.log("req:",relative+url)
            var xhr = new XMLHttpRequest()
            xhr.open("GET",relative+url,true)
            xhr.onreadystatechange = function () {
                if (xhr.readyState === 4) {
                    if (xhr.status >= 200 && xhr.status < 300) {
                        reslove({
                            text(){
                                return new Promise((reslove1,reject1)=>{
                                    reslove1(xhr.response)
                                })
                            }
                        })
                    } else {
                        reject({status:xhr.status})
                    }
                }
            }
            xhr.send(); 
        })
    }
    
)()
